package net.example.model;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.oraycn.omcs.utils.BufferUtils;

import net.example.ggtalk.R;

/**
 * Created by ZN on 2015/12/3.
 */
public enum UserStatus {
    Online(2), Away(3), Busy(4), DontDisturb(5), OffLine(6), Hide(7);

    private int type;

    public static int getUserStatusResource(UserStatus userStatus,boolean isMySelf) {
        int id = 0;
        if(userStatus!=null){
        switch (userStatus) {
            // Online(2), Away(3), Busy(4), DontDisturb(5), OffLine(6), Hide(7);
            case Away:
//                id = R.drawable.status_3;
//                break;
            case Busy:
//                id = R.drawable.status_4;
//                break;
            case DontDisturb:
//                id = R.drawable.status_5;
//                break;
            case Online:
                id = R.drawable.online_icon;
                break;

            case OffLine:
                id = R.drawable.status_6;
                break;
            case Hide:
                if (isMySelf) {
                    id = R.drawable.status_7;
                } else {
                    id = R.drawable.status_6;
                }
                break;
            default:
                break;
        }
        }else{
            id = R.drawable.status_6;
        }

        return  id;
    }

    public static void setImageBackgroundGrayByStatus(UserStatus status, ImageView imageView, ImageView statusView) {
        if(status==null){
            if(statusView!=null) {
                statusView.setVisibility(View.GONE);
            }
        }else {
            switch (status) {
                case OffLine:
                case Hide:
                   // AndroidUI.toGrayImage(imageView); 不做头像灰化处理
                    if (statusView != null) {
                        statusView.setVisibility(View.GONE);
                    }
                    break;
                default:
                  //  AndroidUI.toNormalImage(imageView); 不做头像灰化点亮处理
                    if (statusView != null) {
                        statusView.setVisibility(View.VISIBLE);
                    }
                    break;
            }
        }
    }

    public static void setDisplayNameByStatus(UserStatus status, TextView textView) {
        switch (status){
            case OffLine:
            case Hide:
                textView.setTextColor(Color.DKGRAY);
                break;
            default:
                textView.setTextColor(Color.WHITE);
                break;
        }
    }

    UserStatus(int type) {
        this.type = type;
    }

    public static UserStatus getUserStatusByCode(int code) {
        for (UserStatus type : UserStatus.values()) {
            if (type.getType() == code) {
                return type;
            }
        }
        return null;
    }

    public static byte[] GetStatusBytes(UserStatus status) {
        return BufferUtils.newBuffer(4).writeInt(status.getType()).array();
    }

    public int getType() {
        return type;
    }
}